﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SPC
{
    /// <summary>
    /// 缺陷（瑕疵）数C控制图
    /// 用于控制缺陷数量
    /// </summary>
    class SpcC : ISPC
    {
        double[] c;//组内不良数量
        double cbar;
        
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="NGs">每组不良数量,要求每组样本数相等</param>
        public SpcC(double[] bugs)
        {
            c = bugs;
            cbar = c.Average();
        }
        public double LSL
        { set { } }
        public double USL
        { set { } }
        public double CP()
        {
            return cbar;
        }

        public double CPK()
        {
            return cbar;
        }

        public SCtrlDiagram[] GetCtrlDiagrams()
        {
            double nps = Math.Sqrt(cbar);
            double lcl = cbar - 3 * nps;
            SCtrlDiagram[] diags = new SCtrlDiagram[1];
            diags[0] = new SCtrlDiagram()
            {
                diagramName = DiagramName.c,
                points = c,
                cl = cbar,
                lcl = lcl > 0 ? lcl : 0,
                ucl = cbar + 3 * nps
            };
            
            return diags;
        }

        public double PP()
        {
            return cbar;
        }

        public double PPK()
        {
            return cbar;
        }
    }
}
